﻿using System;
using Hjt212Parser;
using System.Linq;
using Biz.Buffer;
using Biz.EF.Platform;
using log4net;


namespace Biz.Process
{
    /// <summary>
    /// 主要处理校时、阀门状态等指令
    /// </summary>
    public class UplineCmdInstructionBoth
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(UplineCmdInstructionBoth));

        public static void Process1011(PlatformContext pCtx, string content)
        {
            try
            {
                var mn = Parser.GetStringByKey("MN", content);
                if (string.IsNullOrEmpty(mn)) return;
                var letport = CommonInformation.GetLetportByMn(mn);
                if (letport == null) return;
                var datatime = Parser.GetDateTimeByKey("SystemTime", content);
                if (datatime == null) return;
                var qn = Parser.GetStringByKey("QN", content);
                if (string.IsNullOrEmpty(qn)) return;
                var items = pCtx.现场机系统时间.Where(t => t.企业基本信息ID == letport.企业基本信息ID)
                .Where(t => t.设备信息ID == letport.ID)
                .Where(t => !string.IsNullOrEmpty(t.QN) && t.QN.Equals(qn)).ToList();
                foreach (var item in items)
                {
                    item.提取时间 = datatime;
                }
                pCtx.SaveChanges();

            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
    }
}
